package com.snailct.bpp.service.core.handle;

import com.snailct.bpp.commons.utils.SpringContextHolder;
import com.snailct.bpp.service.core.definition.DefaultServiceDefinition;
import com.snailct.bpp.service.core.definition.ServiceDefinition;
import com.snailct.bpp.service.core.reader.DocDefinitionReader;
import com.snailct.bpp.service.core.reader.XmlDefinitionReader;
import org.w3c.dom.Document;

/**
 * Created by huangxa on 2016/7/13.
 */
public class ServiceDefinitionHolder {
    public ServiceDefinition handle(String data){
        XmlDefinitionReader xmlDefinitionReader = new XmlDefinitionReader();
        Document doc = null;
        try {
            doc = xmlDefinitionReader.loadResource(data);
        } catch (Exception e) {
            e.printStackTrace();
        }
        DocDefinitionReader docDefinitionReader = new DocDefinitionReader();
        ServiceDefinition serviceDefinition = docDefinitionReader.parseDoc(doc);
        ServiceRepository serviceRepository  = SpringContextHolder.getBean("serviceRepository");

        DefaultServiceDefinition wsServiceDefinition = (DefaultServiceDefinition) serviceRepository.getServiceDefinition(serviceDefinition);

        wsServiceDefinition.setSendBody(data);
        return wsServiceDefinition;
    }
}
